package com.alternatealerts.client;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AlertsArrayAdapter extends ArrayAdapter<Alert> {
	public static final String TAG = "AlertsArrayAdatper";
	int resource;
	String response;
	Context context;

	public AlertsArrayAdapter(Context context, int textViewResourceId,
			List<Alert> alerts) {
		// TODO Create default constructor
		super(context, textViewResourceId, alerts);
		this.resource = textViewResourceId;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LinearLayout alertView;
		Alert alert = getItem(position);
		
		//Inflate the view
		if(convertView == null){
			alertView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi;
			vi = (LayoutInflater)getContext().getSystemService(inflater);
			vi.inflate(resource, alertView, true);
		}
		else
		{
			alertView = (LinearLayout) convertView;
		}
			//Get the text boxes from the listitem.xml file
	        TextView recordingDate =(TextView) alertView.findViewById(R.id.txtRecordingDate);
	        TextView stationName =(TextView) alertView.findViewById(R.id.txtStationName);
	        stationName.setText(alert.getStation());
	        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	        recordingDate.setText(dateFormat.format(alert.getRecordingDateTime()));
	        return alertView;
		}
	}